# -*- coding: utf-8 -*-
#----------------------------------------------------------------------------#
# testHanziTable.py
# Lars Yencken <lars.yencken@gmail.com>
# vim: ts=4 sw=4 sts=4 et tw=78:
# Fri Dec 22 16:10:17 2006
#
#----------------------------------------------------------------------------# 

import unittest
from hanziTable import *
from www.settings import UNKNOWN_WILDCARD

#----------------------------------------------------------------------------#

def suite():
    testSuite = unittest.TestSuite((
            unittest.makeSuite(HanziTableTestCase)
        ))
    return testSuite

#----------------------------------------------------------------------------#

class HanziTableTestCase(unittest.TestCase):
    """ This class tests the HanziTable class. 
    """
    def setUp(self):
        pass

    def testToKanji(self):
        """ Tests conversion from hanzi to kanji. Some mappings are ambiguous.
        """
        toKanji = getCognateRelation().reverseMap()
        self.assertEqual(toKanji[u'两'], set([u'両', u'两', u'兩']))
        pass
    
    def testToHanzi(self):
        """ Tests conversion from kanji to hanzi. Each mapping is unique.
        """
        toHanzi = getCognateRelation().forwardMap()
        self.assertEqual(toHanzi[u'两'], set([u'两']))
        pass

    def testProofedMapping(self):
        """ Tests that the proofed kanji mappings work for some basic cases.
        """
        relation = getProofedCognateRelation('u')
        normalRelation = getCognateRelation()
        assert relation.isSubRelation(normalRelation)

        self.assertEqual(relation.forwardLabel, 'kanji')
        self.assertEqual(relation.reverseLabel, 'hanzi')
        self.assertEqual(normalRelation.forwardLabel, 'kanji')
        self.assertEqual(normalRelation.reverseLabel, 'hanzi')

        bestToKanji = getProofedCognateRelation('p').reverseMap()
        assert u'団' in bestToKanji[u'团']
        assert u'鬭' not in bestToKanji.get(u'斗', [])

        bestToHanzi = getProofedCognateRelation('p').forwardMap()
        assert u'团' in bestToHanzi[u'団']
        assert u'斗' not in bestToHanzi.get(u'鬭', [])

        assert getProofedCognateRelation('p').isSubRelation(
                getProofedCognateRelation('q')
            )
        assert getProofedCognateRelation('q').isSubRelation(
                getProofedCognateRelation('r')
            )
        assert getProofedCognateRelation('r').isSubRelation(
                getProofedCognateRelation('u')
            )

        return

    def testPixelRelation(self):
        """ Tests the pixel cognate relation.
        """
        scoredRelation = getCognatePixelRelation()
        assert (u'耀', u'耀') in scoredRelation

    def tearDown(self):
        pass

#----------------------------------------------------------------------------#

if __name__ == "__main__":
    unittest.TextTestRunner(verbosity=1).run(suite())

#----------------------------------------------------------------------------#

# vim: ts=4 sw=4 sts=4 et tw=78:

